import request from '../util/httpTool'
import DeviceBatchStatusReq from "../req/DeviceBatchStatusReq";
import DeviceGetReq from "../req/DeviceGetReq";
import DeviceListReq from "../req/DeviceListReq";
import Device from "../res/Device";
import DeviceStatus from "../res/DeviceStatus";
import DeviceSensorDataWithExplain from "../res/DeviceSensorDataWithExplain";
import DeviceSensorData from "../res/DeviceSensorData";

const basePath = 'iot/api/v1/v1/device/'

export function batchDeviceStatus(req: DeviceBatchStatusReq): Promise<DeviceStatus[]> {
    return new Promise<DeviceStatus[]>((resolve, reject) => {
        const res: any = request({
            url: basePath + 'batchDeviceStatus',
            method: 'post',
            data: req
        })
        res.then((data: DeviceStatus[]) => {
            resolve(data)
        }).catch((e: any) => {
            reject(e)
        })
    })
}

export function list(req: DeviceListReq): Promise<Device[]> {
    return new Promise<Device[]>((resolve, reject) => {
        const res: any = request({
            url: basePath + 'list',
            method: 'post',
            data: req
        })
        res.then((data: Device[]) => {
            resolve(data)
        }).catch((e: any) => {
            reject(e)
        })
    })

}

export function get(req: DeviceGetReq): Promise<Device> {
    return new Promise<Device>((resolve, reject) => {
        const res: any = request({
            url: basePath + 'get',
            method: 'post',
            data: req
        })
        res.then((data: Device) => {
            resolve(data)
        }).catch((e: any) => {
            reject(e)
        })
    })
}


